{template 'common/header'}
<ul class="nav nav-tabs">
    <li {if $op == 'display'} class="active" {/if}><a href="{php echo $this->createWebUrl('adv',array('op' =>'display'))}">广告管理</a></li>
    <li{if empty($adv['id']) && $op== 'post'} class="active" {/if}><a href="{php echo $this->createWebUrl('adv',array('op' =>'post'))}">添加广告</a></li>
    {if !empty($adv['id']) &&  $op== 'post'}<li  class="active"><a href="{php echo $this->createWebUrl('adv',array('op' =>'post','id'=>$adv['id']))}">编辑广告</a></li>{/if}
</ul>

{if $op == 'display'}
<link rel="stylesheet" href="../addons/amouse_article/style/css/jquery-ui-tooltip.min.css?v=20140603" />
<script type="text/javascript" src="../addons/amouse_article/style/css/jquery-ui-tooltip.min.js?v=20140601" ></script>


<div class="panel panel-info">
    <div class="panel-heading">筛选</div>
    <div class="panel-body">
        <form role="form" class="form-horizontal" method="get" action="./index.php">
            <input type="hidden" name="m" value="amouse_article" >
            <input type="hidden" name="do" value="adv" >
            <input type="hidden" name="c" value="site" />
            <input type="hidden" name="a" value="entry" />
            <input type="hidden" value="display" name="op">

            <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">关键字</label>
                <div class="col-sm-8">
                    <input type="text" placeholder="搜索广告名称" value="{$_GPC['keyword']}" id="" name="keyword" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <div class="pull-right col-xs-12 col-sm-2 col-lg-1">
                    <button class="btn btn-block"><i class="fa fa-search"></i> 搜索</button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="main panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead class="navbar-inner">
            <tr>
                <th style="width:30px;">ID</th>
                <th>标题</th>
                <th>连接</th>
                <th>广告图片</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {loop $list $adv}
            <tr>
                <td>{$adv['id']}</td>
                <td>{$adv['title']}</td>
                <td>{$adv['link']}</td>
                <td  class="qrcode">
                    <img src="{$_W['attachurl']}{$adv['thumb']}" height="45px" width="45px" />
                </td>
                <td style="text-align:left;">
                    <a href="{php echo $this->createWebUrl('adv', array('op' => 'post', 'id' => $adv['id']))}" class="btn btn-mini btn-primary"><i class="fa fa-edit"></i></a>
                    <a onclick="return confirm('此操作不可恢复，确认吗？'); return false;"
                       href="{php echo $this->createWebUrl('adv', array('id' => $adv['id'],'op'=>'deleteop'))}" title="删除" class="btn btn-mini btn-danger">
                        <i class="fa fa-times"></i></a>

                </td>
            </tr>
            {/loop}
            </tbody>
        </table>
        <div style="margin:0 auto;margin-right: auto;vertical-align: middle;text-align: center;" >
            {$pager}
        </div>
    </div>
</div>
<script>

    $("td.qrcode").tooltip({
        items:'img',
        content: function() {
            return "<img width='300px' height='300px' src='"  + $(this).attr("src") + "'></img>";
        },
        position: {
            my : "right bottom-300",
            collision: "fit"
        }
    });
</script>
{elseif $op == 'post'}

<div class="main">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
        <input type="hidden" name="id" value="{$adv['id']}" />
        <div class="panel panel-default">
        <div class="panel-heading">
            推广设置
        </div>
        <div class="panel-body">

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>标题</label>
                <div class="col-sm-9">
                    <input type="text" id='title' name="title" class="form-control" value="{$adv['title']}" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">类型</label>
                <div class="col-sm-9">
                    <input type="radio" name="type" value="1" id="type_01" {if $adv['type']=='1'}checked="true"{/if}>
                    <label for="type_01">商品推荐</label>
                    <input type="radio" name="type" value="0" id="type_00"  {if $adv['type']=='0'}checked="true"{/if}>
                    <label for="type_00">公众号推荐</label>
                    <input type="radio" name="type" value="2" id="type_00"  {if $adv['type']=='2'}checked="true"{/if}>
                    <label for="type_00">活动推广</label>

                    <span class="help-block">1:商品推荐，直接查看商品链接
                            2:公众号推荐，直接到引导关注
                            3:活动推广，直接显示全图片(图片建议尺寸：300px*100px)。
                    </span>
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">图片</label>
                <div class="col-sm-9">
                    {php echo tpl_form_field_image('thumb', $adv['thumb'])}
                    <span class="help-block">如果选择公众号推荐，上传公众号的二维码。</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">连接</label>
                <div class="col-sm-9">
                 <input type="text" name="link" class="form-control" value="{$adv['link']}" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">描述</label>
                <div class="col-sm-9">
                    <input type="text" name="description" class="form-control" value="{$adv['description']}" />
                </div>
            </div>
        </div>
    </div>
        <div class="form-group col-sm-12">
            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
            <input type="hidden" name="token" value="{$_W['token']}" />
        </div>
    </form>
</div>
<script language='javascript'>
    function formcheck() {
        if ($("#title").isEmpty()) {
            Tip.focus("title", "请填写广告名称!");
            return false;
        }
        return true;
    }
</script>
{/if}